<template>
	<view class="mainpadding">
		<view class="" style="padding-bottom: 170rpx;">
			<view class="ffffff radius mainpadding flexbetween">
				<view class="ershiba zhonghei fonweight">店铺名称</view>
				<input class="textright" placeholder="请输入店铺名称" type="text" v-model="name" />
			</view>
			<uni-data-picker @change="bindPickerChange" :localdata="items" placeholder="请选择住址" popup-title="请选择地区"
				v-model="addressData.county" class="zdy">
				<view class="ffffff radius mainpadding flexbetween margin_top">
					<view class="ershiba zhonghei fonweight">所属省市区县</view>
					<view class="flexright">
						<input class="textright margin_right1" placeholder="点击选择省市区县" v-model="area" disabled="" type="text" />
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</view>
			</uni-data-picker>
			<view class="ffffff radius mainpadding flexbetween margin_top" @click="selectaddressfn">
				<view class="ershiba zhonghei fonweight">店铺地图定位</view>
				<view class="flexright">
					<input class="textright margin_right1" placeholder="点击选择店铺地图定位" disabled="" type="text" v-model="address"/>
					<u-icon name="arrow-right" color="#999999"></u-icon>
				</view>
			</view>
			<view class="ffffff radius mainpadding flexbetween margin_top">
				<view class="ershiba zhonghei fonweight">店铺详细地址</view>
				<input class="textright" placeholder="请输入店铺详细地址" type="text" v-model="address_detail"/>
			</view>
			<view class="ffffff radius mainpadding flexbetween margin_top">
				<view class="ershiba zhonghei fonweight">负责人姓名</view>
				<input class="textright" placeholder="请输入负责人姓名" type="text" v-model="fr_name"/>
			</view>
			<view class="ffffff radius mainpadding flexbetween margin_top">
				<view class="ershiba zhonghei fonweight">负责人电话</view>
				<input class="textright" placeholder="请输入负责人电话" type="number"  v-model="fr_mobile"/>
			</view>
			<view class="ffffff radius mainpadding flexbetween margin_top">
				<view class="ershiba zhonghei fonweight">店铺联系电话</view>
				<input class="textright" placeholder="请输入店铺联系电话" type="number"  v-model="tel"/>
			</view>
			<!-- <uni-data-picker @change="bindPickerChangecat" :localdata="categoryList" placeholder="请选择商家类别" popup-title="请选择商家类别"
				v-model="category_id" class="zdy">
				<view class="ffffff radius mainpadding flexbetween margin_top">
					<view class="ershiba zhonghei fonweight">选择商家类别</view>
					<view class="flexright">
						<input class="textright margin_right1" placeholder="请选择商家类别" type="text" disabled="" v-model="category_text"/>
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</view>
			</uni-data-picker> -->
			
			<view class="ffffff radius mainpadding flexbetween margin_top">
				<view class="ershiba zhonghei fonweight">营业时间</view>
				<input class="textright margin_right1" placeholder="例如8:00-18:00" type="text" v-model="yysj"/>
			</view>
			<view class="ffffff radius mainpadding  margin_top">
				<view class="ershiba zhonghei fonweight">店铺logo</view>
				<image class="upimg margin_top" src="../static/images/system/upimg.png" v-if="logo_text==''" @click="upflag=0;uploadImg()" mode=""></image>
				<image class="upimg margin_top" :src="logo_text" v-else @click="upflag=0;uploadImg()" mode=""></image>
			</view>
			<view class="ffffff radius mainpadding  margin_top">
				<view class="flexleft flex_wrap ">
					<view class="flexcolumn sanshis">
						<view class="ershiba zhonghei fonweight">门头照</view>
						<image class="upimg margin_top" src="../static/images/system/upimg.png" v-if="mtz_image_text==''" @click="upflag=1;uploadImg()" mode=""></image>
						<image class="upimg margin_top" :src="mtz_image_text" v-else @click="upflag=1;uploadImg()" mode=""></image>
					</view>
				</view>
			</view>
			<view class="ffffff radius mainpadding  margin_top">
				<view class="ershiba zhonghei fonweight">门店环境照</view>
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in hjz_image_text" :key="index">
						<!-- 已上传 -->
						<view class="listleftimg">
							<image class="listleftimg radius" :src="item" mode=""></image>
							<view class="shanchu" @click="deleteimg(hjz_image,hjz_image_text,index)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="upflag=2;uploadImg(4)">
						<!-- 未上传 -->
						<view class="huibox listleftimg"></view>
					</view>
				</view>
			</view>
			<view class="ffffff radius mainpadding  margin_top">
				<view class="ershiba zhonghei fonweight">荣誉资质照</view>
				<view class="flexleft flex_wrap">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in ryzz_images_text" :key="index">
						<!-- 已上传 -->
						<view class="listleftimg">
							<image class="listleftimg radius" :src="item" mode=""></image>
							<view class="shanchu" @click="deleteimg(ryzz_images,ryzz_images_text,index)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="upflag=7;uploadImg(4)">
						<!-- 未上传 -->
						<view class="huibox listleftimg"></view>
					</view>
				</view>
			</view>
			<!-- <view class=" margin_top">
				<image class="scyyzz" src="../static/images/system/scyyzz.png" mode="" v-if="yyzz_image_text==''" @click="upflag=4;uploadImg()" ></image>
				<image class="scyyzz" mode="" :src="yyzz_image_text" v-else @click="upflag=4;uploadImg()"></image>
			</view>
			<view class="flexbetween margin_top">
				<image class="sfzfm" src="../static/images/system/sfzzm.png" mode="" v-if="fr_zimage_text==''" @click="upflag=5;uploadImg()" ></image>
				<image class="sfzfm" :src="fr_zimage_text" v-else @click="upflag=5;uploadImg()"></image>
				<image class="sfzfm" src="../static/images/system/sfzfm.png" mode="" v-if="fr_fimage_text==''" @click="upflag=6;uploadImg()" ></image>
				<image class="sfzfm" :src="fr_fimage_text" v-else @click="upflag=6;uploadImg()"></image>
			</view> -->
		</view>
		<view class="bigbtn margin_top" @click="submit">确认修改</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	import citys from "../static/city/city.js"
	export default {
		data() {
			return {
				addressData: {
					province: "", //省
					city: "", //市
					county: "", //区
				},
				area: "",
				items: citys.data,
				name:"",
				address:"",
				fr_name:"",
			address_detail:"",
			fr_mobile:"",
			tel:"",
				category_id:"",
				category_text:"",
				yysj:"",
				logo:"",
				logo_text:"",
				mtz_image:"",
				mtz_image_text:"",
				hjz_image:[],
				hjz_image_text:[],
				ryzz_images:[],
				ryzz_images_text:[],
				yyzz_image:"",
				yyzz_image_text:"",
				fr_zimage:"",
				fr_zimage_text:"",
				fr_fimage:"",
				fr_fimage_text:"",
				upflag:0,
				categoryList:[],
				listid:"",
				latitude:"",
				longitude:"",
			}
		},
		onLoad(options) {
			if(options.id){
				this.listid = options.id
				this.getdetail()
			}
		},
		methods: {
			deleteimg(upImg,upImgs_text,index){
				upImg.splice(index,1)
				upImgs_text.splice(index,1)
			},
			selectaddressfn(){
				let _this = this
				uni.chooseLocation({
					success:function(response){
						console.log('位置名称:',response);
						_this.address = response.name
						_this.latitude = response.latitude
						_this.longitude = response.longitude
					}
				})
			},
			getdetail(){
				httpRequest.request('/api/shopcl/myShopDetail', 'GET', {
					shop_id: this.listid
				}).then(res => {
					let data = res.data
					this.name = data.name
					this.address = data.address
					this.fr_name = data.fr_name
					this.address_detail = data.address_detail
					this.fr_mobile = data.fr_mobile
					this.tel = data.tel
					this.yysj = data.yysj
					this.logo = data.logo
					this.logo_text = data.logo_text
					this.mtz_image = data.mtz_image
					this.mtz_image_text = data.mtz_image_text
					this.hjz_image = data.hjz_image.split(",")
					this.hjz_image_text = data.hjz_image_text
					this.ryzz_images = data.ryzz_images.split(",")
					this.ryzz_images_text = data.ryzz_images_text
					this.yyzz_image = data.yyzz_image
					this.yyzz_image_text = data.yyzz_image_text
					this.fr_zimage = data.fr_zimage
					this.fr_zimage_text = data.fr_zimage_text
					this.fr_fimage = data.fr_fimage
					this.fr_fimage_text = data.fr_fimage_text
					this.latitude = data.latitude
					this.longitude = data.longitude
					this.area = data.cityinfo
					// this.category_text = data.category.name
					this.addressData = {
						province: data.province, //省
						city: data.city, //市
						county: data.district, //区
					}
					
				})
			},
			submit(){
				if (this.name == "") {
					httpRequest.toast("请输入店铺名称")
					return
				}
				if (this.addressData.province == "") {
					httpRequest.toast("请选择所属省市区县")
					return
				}
				if (this.address == "") {
					httpRequest.toast("请选择店铺地图定位”")
					return
				}
				if (this.address_detail == "") {
					httpRequest.toast("请输入店铺详细地址")
					return
				}
				if (this.fr_name == "") {
					httpRequest.toast("请输入负责人姓名")
					return
				}
				if (this.fr_mobile == "") {
					httpRequest.toast("请输入负责人电话")
					return
				}
				if (this.tel == "") {
					httpRequest.toast("请输入店铺联系电话")
					return
				}
				if (this.yysj == "") {
					httpRequest.toast("请输入营业时间")
					return
				}
				if (this.logo == "") {
					httpRequest.toast("请上传店铺logo")
					return
				}
				if (this.mtz_image == "") {
					httpRequest.toast("请上传门头照")
					return
				}
				if (this.hjz_image.length == 0) {
					httpRequest.toast("请上传门店环境照")
					return
				}
				if (this.ryzz_images.length == 0) {
					httpRequest.toast("请上传荣誉资质照")
					return
				}
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				let url = "/api/shopcl/editShopInfo"
				let data = {
					name: this.name,
					province: this.addressData.province,
					city: this.addressData.city,
					district: this.addressData.county,
					address: this.address,
					fr_name: this.fr_name,
					address_detail:this.address_detail,
					fr_mobile: this.fr_mobile,
					tel:this.tel,
					yysj: this.yysj,
					logo: this.logo,
					mtz_image: this.mtz_image,
					hjz_image: this.hjz_image.join(),
					ryzz_images: this.ryzz_images.join(),
					hjz1_image: this.hjz1_image,
					latitude: this.latitude,
					longitude: this.longitude,
					id:this.listid
				}
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			
			uploadImg(val) {
				if(!val){
					val = 1
				}
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(val, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(val, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					if(this.upflag==0){
						this.logo = res.url;
						this.logo_text = image_item;
					}else if(this.upflag==1){
						this.mtz_image = res.url;
						this.mtz_image_text = image_item;
					}else if(this.upflag==2){
						this.hjz_image.push(res.url);
						this.hjz_image_text.push(image_item);
					}else if(this.upflag==4){
						this.yyzz_image = res.url;
						this.yyzz_image_text = image_item;
					}else if(this.upflag==5){
						this.fr_zimage = res.url;
						this.fr_zimage_text = image_item;
					}else if(this.upflag==6){
						this.fr_fimage = res.url;
						this.fr_fimage_text = image_item;
					}else if(this.upflag==7){
						this.ryzz_images.push(res.url);
						this.ryzz_images_text.push(image_item);
					}
				}).catch(err => {});
			},
			bindPickerChange(val) {
				let area = val.detail.value
				let area_text = [area[0].text, area[1].text, area[2].text];
				this.area = area_text.join("/")
				this.addressData.province = area[0].value;
				this.addressData.city = area[1].value;
				this.addressData.county = area[2].value;
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	// .shangctp {
	// 	width: 26rpx;
	// 	height: 26rpx;
	// 	background-size: 100% 100%;
	// 	background-image: url('../static/images/system/shangchuantp.png');
	// }
	.huibox {
		width: 147rpx;
		height: 147rpx;
		background: #F6F6F6;
		border-radius: 10rpx;
		background-size: 100% 100%;
		background-image: url('../static/images/system/upimg.png');
	}
	.sfzfm {
		width: 336rpx;
		height: 291rpx;
	}

	.scyyzz {
		width: 100%;
		height: 291rpx;
	}

	.shanchu {
		width: 32rpx;
		height: 32rpx;
		position: absolute;
		top: 0;
		right: 0;
		background-size: 100% 100%;
		background-image: url('@/static/images/system/shanchu1.png');
	}

	.upimg {
		width: 194rpx;
		height: 194rpx;
	}
</style>